package com.ctshk.app.user.controller;

import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.SystemError;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.utils.Assert;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.user.req.GeneralSmsCaptchaReq;
import com.ctshk.rpc.user.req.SmsCaptchaReq;
import com.ctshk.rpc.user.service.IUserValidateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 *  通用验证码接口
 * </p>
 *
 * @author 李新科
 * @date 2021/5/27 9:56
 */
@Api(value="通用验证码接口", tags="通用验证码接口")
@RestController
@RequestMapping("/sms")
public class SmsController extends BaseController {

    @DubboReference
    private IUserValidateService userValidateService;

    @ApiOperation(value="发送验证码", notes="发送验证码")
    @PostMapping("/send")
    public Result smsUniversalCaptcha(@RequestBody @Valid GeneralSmsCaptchaReq req) throws Exception{
        return userValidateService.sendCode(req.getContactMobileAreaCode(),req.getContactNumber());
    }

    @ApiOperation(value="测试-验证验证码", notes="测试-验证验证码")
    @PostMapping("/check")
    public Result check(@RequestBody @Valid GeneralSmsCaptchaReq req) throws Exception{
        return Result.success(userValidateService.checkCode(req.getContactMobileAreaCode(),req.getContactNumber(),req.getCode()));
    }


}
